package com.zjm.collections.map;

import java.util.concurrent.TimeUnit;

public class VisibilityDemo {
    // 运行标志
    public String flag = "true";

    public static void main(String[] args) throws InterruptedException {
        VisibilityDemo demo1 = new VisibilityDemo();
        System.out.println("代码开始了");
        System.out.println(demo1);
        Thread thread1 = new Thread(() -> {
            int i = 0;
            while ("true".equals(demo1.flag)) {
                //System.out.println("*****");
                i++;
            }
            System.out.println(demo1);
        });
        thread1.start();
        TimeUnit.SECONDS.sleep(2);
        // 设置is为false，使上面的线程结束while循环
        demo1.flag = "fl";
        System.out.println("被置为false了.");
    }
}
